import React from 'react'
import { Form, Tag, Input, Upload, message, Button } from 'antd'
import request from '@/utils/request'
import { UploadOutlined } from '@ant-design/icons'

import Enterprise from '../add/enterprise'

import Personal from '../add/personal'

const navStyle = {
    borderLeft: "4px solid #4685FD",
    fontWeight: 600,
    paddingLeft: "6px",
    fontSize: "16px"
}
export default (props: any) => {
    const { form, apply_type, id, close } = props

    const handleUploadChange = (info: any): any => {
        let fileList = info.fileList;
        fileList = fileList.slice(-1);
        if (info.file.status === 'done') {
            message.success(`${info.file.name}文件上传成功`);
            fileList[0].url = fileList[0]['response']['data']['filePath'];
        }
        return fileList
    };

    const onFinish = (values: any) => {

        if (apply_type == 1) {
            if (values.id_card_front && values.id_card_front.length > 0) {
                values.id_card_front = values.id_card_front[0]['url'];
            }
            if (values.id_card_back && values.id_card_back.length > 0) {
                values.id_card_back = values.id_card_back[0]['url'];
            }
        }
        if (apply_type == 2) {
            if (values.law_id_card_front && values.law_id_card_front.length > 0) {
                values.law_id_card_front = values.law_id_card_front[0]['url'];
            }
            if (values.law_id_card_back && values.law_id_card_back.length > 0) {
                values.law_id_card_back = values.law_id_card_back[0]['url'];
            }
        }

        values.apply_type = apply_type
        request(`/store/update-account/${id}`, {
            method: 'put',
            data: { ...values },
        }).then((result) => {
            if (result.code === 200) {
                message.success(result.message, 1, () => {
                    close()
                })
            }
        })
    }

    return (
        <Form
            labelCol={{ span: 4 }}
            wrapperCol={{ span: 16 }}
            form={form}
            onFinish={onFinish}
        >
            <div style={{ padding: "15px 0 0 15px" }}>
                <nav style={navStyle}>联系人信息</nav>
                <Form.Item label="申请类型">
                    <Tag color="cyan">
                        {apply_type === 1 && "个人店铺"}
                        {apply_type === 2 && "企业店铺"}
                    </Tag>
                </Form.Item>
            </div>

            {apply_type === 1 && <Personal />}
            {apply_type === 2 && <Enterprise />}

            <Form.Item
                wrapperCol={{ offset: 4 }}
            >
                <Button type="primary" htmlType="submit">保存</Button>
                <Button style={{ marginLeft: "6px" }} onClick={close}>取消</Button>
            </Form.Item>
        </Form>
    )
}